﻿Public Class Alumno
    Public arr As Hashtable
    Public arr2 As Hashtable
    Private contador As Integer
    Private contador2 As Integer
    Dim cv As Integer

    'Load
    Private Sub Alumno_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Lista de Cursos
        arr = New Hashtable
        arr2 = New Hashtable
        Label8.Text = Form1.tb_usuario.Text
        info.Text = "Aplicación iniciada"
        Dim c As Curso = New Curso("Curso de Programacion en Moviles Android", 12333221, 1, "Curso", "cursos@urjc.es", "Mostoles", "13/03/2012", "www.urjc.cursos.es", "Cursos abierto")
        arr.Add(contador, c)
        contador = contador + 1
        c = New Curso("Escursion por la Pedriza", 23423421, 1, "Salida", "delegacionalumnos@urjc.es", "Mostoles", "13/03/2012", "www.urjc.cursos.es", "Cursos abierto")
        arr.Add(contador, c)
        contador = contador + 1
        c = New Curso("Seminario de Artes Graficas", 12312312, 1, "Seminario", "seminarios@urjc.es", "Funelabrada", "13/03/2012", "www.urjc.cursos.es", "")
        arr.Add(contador, c)
        contador = contador + 1
        c = New Curso("Curso de inicio a Photoshop", 65776867, 1, "Curso", "cursos@urjc.es", "Mostoles", "13/03/2012", "www.urjc.cursos.es", "Cursos abierto")
        arr.Add(contador, c)
        contador = contador + 1
        c = New Curso("Taller de desarrollo", 8906578, 1, "Taller", "cursos@urjc.es", "Mostoles", "13/03/2012", "www.urjc.cursos.es", "Cursos abierto")
        arr.Add(contador, c)
        contador = contador + 1
        c = New Curso("Concurso de tapas", 5685, 1, "Concurso", "delegacionalumnos@urjc.es", "Mostoles", "13/03/2012", "www.urjc.cursos.es", "Con premios")
        arr.Add(contador, c)
        contador = contador + 1

        'Preferencias
        ck_act.Checked = True
        ck_charlas.Checked = True
        ck_otros.Checked = True
        ck_rec.Checked = True
        ck_sem.Checked = True

        cb_act.SelectedIndex = 0
        cb_sem.SelectedIndex = 1
        cb_otros.SelectedIndex = 2
        cb_char.SelectedIndex = 3
    End Sub

    'PESTAÑA MIS CURSOS

    'Seleccionar un curso
    Private Sub ListBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox2.SelectedIndexChanged
        If ListBox2.SelectedIndex <> -1 Then
            ToolStripButton5.Enabled = True
            ToolStripButton6.Enabled = True
            ToolStripButton7.Enabled = True
            ToolStripButton8.Enabled = True
        Else
            ToolStripButton5.Enabled = False
            ToolStripButton6.Enabled = False
            ToolStripButton7.Enabled = False
            ToolStripButton8.Enabled = False
        End If

        For Each item As Object In arr2.Values
            If (CType(item, Curso).p_nombre) = ListBox2.SelectedItem Then
                RichTextBox2.Text = "ID: " & CType(item, Curso).p_id & vbNewLine & _
                    "Nombre: " & CType(item, Curso).p_nombre & vbNewLine & _
                    "Numero de Creditos: " & CType(item, Curso).p_creditos & vbNewLine & _
                    "Tipo: " & CType(item, Curso).p_tipo & vbNewLine & _
                    "Lugar: " & CType(item, Curso).p_lugar & vbNewLine & _
                    "Fecha: " & CType(item, Curso).p_fecha & vbNewLine & _
                    "E-mail: " & CType(item, Curso).p_correo & vbNewLine & _
                    "Pagina Web: " & CType(item, Curso).p_pagina & vbNewLine & _
                    "Informacion Adicional: " & CType(item, Curso).p_info & vbNewLine
                cv = arr2.Count
            End If
        Next
    End Sub

    'Combobox key press
    Private Sub ComboBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles ComboBox1.KeyPress, ComboBox6.KeyPress
        e.Handled = True
    End Sub

    'BARRA DE DESPLAZAMIENTO MIS CURSOS
    'Anterior
    Private Sub ToolStripButton6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton6.Click
        ListBox2.SelectedIndex = ListBox2.SelectedIndex - 1
    End Sub

    'Siguiente
    Private Sub ToolStripButton7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton7.Click
        ListBox2.SelectedIndex = ListBox1.SelectedIndex + 1
    End Sub

    'Primer elemento
    Private Sub ToolStripButton5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton5.Click
        ListBox2.SelectedIndex = 0
    End Sub

    'Ultimo Elemento
    Private Sub ToolStripButton8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton8.Click
        ListBox2.SelectedIndex = ListBox1.Items.Count() - 1
    End Sub






    'PESTAÑA TODOS LOS CURSOS

    'Buscar
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Buscar(TextBox7.Text, 0, "")
    End Sub

    'Seleccionar un elemento
    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
        If ListBox1.SelectedIndex <> -1 Then
            ToolStripButton1.Enabled = True
            ToolStripButton2.Enabled = True
            ToolStripButton3.Enabled = True
            ToolStripButton4.Enabled = True
        Else
            ToolStripButton1.Enabled = False
            ToolStripButton2.Enabled = False
            ToolStripButton3.Enabled = False
            ToolStripButton4.Enabled = False
        End If

        For Each item As Object In arr.Values
            If (CType(item, Curso).p_nombre) = ListBox1.SelectedItem Then
                RichTextBox1.Text = "ID: " & CType(item, Curso).p_id & vbNewLine & _
                    "Nombre: " & CType(item, Curso).p_nombre & vbNewLine & _
                    "Numero de Creditos: " & CType(item, Curso).p_creditos & vbNewLine & _
                    "Tipo: " & CType(item, Curso).p_tipo & vbNewLine & _
                    "Lugar: " & CType(item, Curso).p_lugar & vbNewLine & _
                    "Fecha: " & CType(item, Curso).p_fecha & vbNewLine & _
                    "E-mail: " & CType(item, Curso).p_correo & vbNewLine & _
                    "Pagina Web: " & CType(item, Curso).p_pagina & vbNewLine & _
                    "Informacion Adicional: " & CType(item, Curso).p_info & vbNewLine
                cv = arr.Count
            End If
        Next
    End Sub

    'Añadir favorito
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        For Each item As Object In arr.Values
            If (CType(item, Curso).p_nombre) = ListBox1.SelectedItem Then
                Dim c As Curso = New Curso("Curso de Programacion en Moviles Android", 12333221, 1, "Curso", "cursos@urjc.es", "Mostoles", "13/03/2012", "www.urjc.cursos.es", "Cursos abierto")
                arr2.Add(contador2, c)
                contador2 = contador2 + 1
            End If
        Next
        info.Text = "Curso añadido a favoritos"
        Buscar2("", 0, "")
    End Sub

    'Filtro
    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        If ComboBox1.SelectedIndex = 0 Then
            Buscar(TextBox7.Text, 0, "")
        Else
            Buscar(TextBox7.Text, 0, ComboBox1.Text)
        End If
    End Sub

    'BARRA DE DESPLAZAMIENTO TODOS LOS CURSOS
    'Anterior
    Private Sub ToolStripButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton2.Click
        ListBox1.SelectedIndex = ListBox1.SelectedIndex - 1
    End Sub

    'Siguiente
    Private Sub ToolStripButton3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton3.Click
        ListBox1.SelectedIndex = ListBox1.SelectedIndex + 1
    End Sub

    'Primer elemento
    Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
        ListBox1.SelectedIndex = 0
    End Sub

    'Ultimo Elemento
    Private Sub ToolStripButton4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton4.Click
        ListBox1.SelectedIndex = ListBox1.Items.Count() - 1
    End Sub








    'PESTAÑA PREFERENCIAS

    'Preferencias Predeterminadas
    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        ck_act.Checked = True
        ck_charlas.Checked = True
        ck_otros.Checked = True
        ck_rec.Checked = True
        ck_sem.Checked = True

        cb_act.SelectedIndex = 0
        cb_sem.SelectedIndex = 1
        cb_otros.SelectedIndex = 2
        cb_char.SelectedIndex = 3

        info.Text = "Preferencias predeterminadas establecidas"
    End Sub

    'Guardar Preferencias
    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        info.Text = "Cambio de las preferencias guardado"
    End Sub






    'FUNCIONES

    'Buscar
    Private Sub Buscar(ByVal cadena As String, ByVal flag As Integer, ByVal filtro As String)
        Dim cont As Integer = 0
        ListBox1.Items.Clear()
        For Each item As Object In arr.Values
            If flag = 0 Then
                If (cadena <> "") Then
                    If filtro <> "" Then
                        If (CType(item, Curso).p_nombre).StartsWith(cadena) And (CType(item, Curso).p_tipo).StartsWith(filtro) Then
                            ListBox1.Items.Add(CType(item, Curso).p_nombre)
                            RichTextBox1.Text = ""
                            cont = cont + 1
                        End If
                    Else
                        If (CType(item, Curso).p_nombre).StartsWith(cadena) Then
                            ListBox1.Items.Add(CType(item, Curso).p_nombre)
                            RichTextBox1.Text = ""
                            cont = cont + 1
                        End If
                    End If
                Else
                    If filtro <> "" Then
                        If (CType(item, Curso).p_tipo).StartsWith(filtro) Then
                            ListBox1.Items.Add(CType(item, Curso).p_nombre)
                            RichTextBox1.Text = ""
                            cont = cont + 1
                        End If
                    Else
                        ListBox1.Items.Add(CType(item, Curso).p_nombre)
                        RichTextBox1.Text = ""
                        cont = cont + 1
                    End If
                End If
            End If
        Next

        If cont = 0 Then
            ListBox1.Items.Clear()
            info.Text = "No se han encontrado coincidencias"
        Else
            info.Text = "Se encontraron " & cont & " coincidencias"
        End If
    End Sub

    'Buscar Mis Cursos
    Private Sub Buscar2(ByVal cadena As String, ByVal flag As Integer, ByVal filtro As String)
        Dim cont As Integer = 0
        ListBox2.Items.Clear()
        For Each item As Object In arr2.Values
            If flag = 0 Then
                If (cadena <> "") Then
                    If filtro <> "" Then
                        If (CType(item, Curso).p_nombre).StartsWith(cadena) And (CType(item, Curso).p_tipo).StartsWith(filtro) Then
                            ListBox2.Items.Add(CType(item, Curso).p_nombre)
                            RichTextBox2.Text = ""
                            cont = cont + 1
                        End If
                    Else
                        If (CType(item, Curso).p_nombre).StartsWith(cadena) Then
                            ListBox2.Items.Add(CType(item, Curso).p_nombre)
                            RichTextBox2.Text = ""
                            cont = cont + 1
                        End If
                    End If
                Else
                    If filtro <> "" Then
                        If (CType(item, Curso).p_tipo).StartsWith(filtro) Then
                            ListBox2.Items.Add(CType(item, Curso).p_nombre)
                            RichTextBox2.Text = ""
                            cont = cont + 1
                        End If
                    Else
                        ListBox2.Items.Add(CType(item, Curso).p_nombre)
                        RichTextBox2.Text = ""
                        cont = cont + 1
                    End If
                End If
            End If
        Next

        If cont = 0 Then
            ListBox2.Items.Clear()
            info.Text = "No se han encontrado coincidencias"
        Else
            info.Text = "Se encontraron " & cont & " coincidencias"
        End If
    End Sub





    Private Sub ToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem1.Click
        Close()
    End Sub
End Class